/**
 * 智慧社区管理系统 - 移动端安防管理API接口
 * @author Wu.Liang
 * @date 2025-01-21
 * @description 移动端工程位于smart-community-app文件夹，严格遵循架构总览中的项目结构规范
 */

import request from './request'

// 安防状态管理API
export const securityStatusApi = {
  // 获取安防状态
  getSecurityStatus: () => {
    return request.get('/api/security/status')
  },

  // 更新安防状态
  updateSecurityStatus: (data) => {
    return request.put('/api/security/status', data)
  },

  // 获取门禁状态
  getDoorLockStatus: () => {
    return request.get('/api/security/door-lock/status')
  },

  // 控制门禁
  controlDoorLock: (doorId, action) => {
    return request.post(`/api/security/door-lock/${doorId}/${action}`)
  }
}

// 访客管理API
export const visitorApi = {
  // 分页查询访客列表
  getVisitorList: (params) => {
    return request.get('/api/security/visitors', { params })
  },

  // 获取访客详情
  getVisitorDetail: (visitorId) => {
    return request.get(`/api/security/visitors/${visitorId}`)
  },

  // 创建访客申请
  createVisitor: (data) => {
    return request.post('/api/security/visitors', data)
  },

  // 更新访客信息
  updateVisitor: (visitorId, data) => {
    return request.put(`/api/security/visitors/${visitorId}`, data)
  },

  // 删除访客
  deleteVisitor: (visitorId) => {
    return request.delete(`/api/security/visitors/${visitorId}`)
  },

  // 审核访客申请
  approveVisitor: (visitorId, action) => {
    return request.post(`/api/security/visitors/${visitorId}/approve`, { action })
  },

  // 获取访客二维码
  getVisitorQrCode: (visitorId) => {
    return request.get(`/api/security/visitors/${visitorId}/qrcode`)
  }
}

// 门禁记录API
export const accessRecordApi = {
  // 分页查询门禁记录
  getAccessRecordList: (params) => {
    return request.get('/api/security/access-records', { params })
  },

  // 获取门禁记录详情
  getAccessRecordDetail: (recordId) => {
    return request.get(`/api/security/access-records/${recordId}`)
  },

  // 创建门禁记录
  createAccessRecord: (data) => {
    return request.post('/api/security/access-records', data)
  },

  // 获取门禁统计
  getAccessStatistics: (params) => {
    return request.get('/api/security/access-records/statistics', { params })
  }
}

// 监控管理API
export const monitorApi = {
  // 获取监控设备列表
  getMonitorList: (params) => {
    return request.get('/api/security/monitors', { params })
  },

  // 获取监控设备详情
  getMonitorDetail: (monitorId) => {
    return request.get(`/api/security/monitors/${monitorId}`)
  },

  // 获取监控实时画面
  getMonitorStream: (monitorId) => {
    return request.get(`/api/security/monitors/${monitorId}/stream`)
  },

  // 获取监控录像列表
  getMonitorRecordings: (monitorId, params) => {
    return request.get(`/api/security/monitors/${monitorId}/recordings`, { params })
  },

  // 获取监控录像下载链接
  getRecordingDownloadUrl: (recordingId) => {
    return request.get(`/api/security/recordings/${recordingId}/download`)
  }
}

// 报警管理API
export const alarmApi = {
  // 分页查询报警记录
  getAlarmList: (params) => {
    return request.get('/api/security/alarms', { params })
  },

  // 获取报警详情
  getAlarmDetail: (alarmId) => {
    return request.get(`/api/security/alarms/${alarmId}`)
  },

  // 处理报警
  handleAlarm: (alarmId, data) => {
    return request.post(`/api/security/alarms/${alarmId}/handle`, data)
  },

  // 获取报警设置
  getAlarmSettings: () => {
    return request.get('/api/security/alarms/settings')
  },

  // 更新报警设置
  updateAlarmSettings: (data) => {
    return request.put('/api/security/alarms/settings', data)
  },

  // 获取报警统计
  getAlarmStatistics: (params) => {
    return request.get('/api/security/alarms/statistics', { params })
  }
}

// 安防设置API
export const securitySettingApi = {
  // 获取安防系统设置
  getSecuritySettings: () => {
    return request.get('/api/security/settings')
  },

  // 更新安防系统设置
  updateSecuritySettings: (data) => {
    return request.put('/api/security/settings', data)
  },

  // 获取权限配置
  getPermissionConfig: () => {
    return request.get('/api/security/permissions')
  },

  // 更新权限配置
  updatePermissionConfig: (data) => {
    return request.put('/api/security/permissions', data)
  },

  // 获取设备配置
  getDeviceConfig: () => {
    return request.get('/api/security/devices/config')
  },

  // 更新设备配置
  updateDeviceConfig: (data) => {
    return request.put('/api/security/devices/config', data)
  }
}

// 默认导出
export default {
  securityStatusApi,
  visitorApi,
  accessRecordApi,
  monitorApi,
  alarmApi,
  securitySettingApi
}
